package com.netrain.ehp.gateway.config;

import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;

import lombok.SneakyThrows;

/**
 * @author luao
 * @date 2022/1/10 2:23 下午
 **/
@Configuration
public class AppConfiguration {

    @SneakyThrows
    @Bean
    public ConfigService configService(NacosConfigProperties nacosProperties) {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.SERVER_ADDR, nacosProperties.getServerAddr());
        properties.put(PropertyKeyConst.USERNAME, nacosProperties.getUsername());
        properties.put(PropertyKeyConst.PASSWORD, nacosProperties.getPassword());
        properties.put(PropertyKeyConst.NAMESPACE, nacosProperties.getNamespace());
        return NacosFactory.createConfigService(properties);
    }
}
